<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" href="../css/elementui.css">
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <script src="../script/elementui.js"></script>
    <style>
        .box {
            width: 100%;
            display: flex;
            flex-direction: column;
        }

        .form {
            width: 100%;
            height: auto;
        }

        .content {
            padding: 0 50px;
        }

        .van-field {
            width: 33.33%;
            float: left;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-field__control {
            border-bottom: 2px solid #e6c678;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .head .van-row .van-col,
        .content .van-row .van-col {
            margin-bottom: 8px;
            text-align: center;
            font-weight: 300;
            color: #e6c678;
            font-size: 14px;
        }

        .content .van-row .van-col .van-field {
            padding: 0;
            background: #fff;
            border: 1px solid #cecece;
            border-radius: 5px;
        }

        .content .van-row .van-col .van-field__control {
            color: #000;
        }

        @keyframes load {
            0% {
                box-shadow: inset 0px 0px 100px 10px rgba(61, 134, 208, 0.6);
            }

            100% {
                box-shadow: inset 0px 0px 20px 10px rgba(61, 134, 208, 0.1);
            }
        }

        .green {
            color: green;
        }

        .red {
            color: red;
        }

        .yellow {
            color: yellow;
        }

        .right-button .van-button {
            margin-left: 5px;
            min-width: 100px;
        }

        .scanImg img {
            width: 40px;
            height: 40px;
        }

        .devicePop {
            height: 50%;
            overflow: auto;
        }

        .devicePop .van-col {
            padding: 5px 8px;
            text-align: center;
        }

        .devicePop .van-col .van-button {
            width: 100%;
        }

        .devicePop .van-col .van-button .van-button__text {
            color: #090909;
        }

        .scanPop {
            width: 160px;
            height: 180px;
            text-align: center;
            background-color: transparent;
            margin: 0;
            padding: 0;
        }

        .van-icon-enlarge {
            font-size: 150px;
            color: #e6c678;
            margin: 0;
            padding: 0;
        }

        .inputClass {
            opacity: 0;
            width: 150px;
        }

        .scanLine {
            position: absolute;
            z-index: 2;
            width: 66%;
            height: 2px;
            transform: translateX(25%);
            background-color: #e6c678;
            animation: scanLineMove 2s infinite;
        }

        .newClass {
            color: red;
        }

        @keyframes scanLineMove {
            from {
                top: 30px;
            }

            to {
                top: 120px;
            }
        }

        .el-radio.is-bordered.is-checked {
            border-color: #e6c678;
        }

        .el-radio__input.is-checked .el-radio__inner {
            border-color: #e6c678;
            background: #e6c678;
        }

        .el-radio__input.is-checked+.el-radio__label {
            color: #e6c678;
        }

        .topLeft {
            width: 50%;
            padding-left: 5px;
        }

        .top .van-button {
            margin-top: 10px;
            margin-left: 5px;
            padding: 10px 20px;
        }

        .el-radio__label {
            color: #fff;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <div class="top">
                <div class="topLeft">
                    <van-button size="small" color="linear-gradient(#fffeaa, #c07d39)" type="primary"
                        @click="onClickLeft">返回</van-button>
                </div>
                <div class="topRight">
                </div>
            </div>
            <div class="content">
                <div class="form">
                    <van-field v-model="formData.MouldNo" label="模具编号：" readonly @click="openBaseScreen('模具')">
                    </van-field>
                    <van-field v-model="formData.ProductName" label="模具名称：" readonly>
                    </van-field>
                    <van-field v-model="formData.unKeepTime" label="开始保养日期：" readonly></van-field>
                    <van-field v-model="formData.unKeepUserName" label="保养人：" readonly>
                    </van-field>
                    <van-field v-model="formData.BYReason" label="保养原因：">
                    </van-field>
                </div>

                <div class="table">
                    <table class="table-full">
                        <tr>
                            <th nowrap="nowrap">保养项目</th>
                            <!-- <th nowrap="nowrap">保养周期</th> -->
                            <th nowrap="nowrap">保养结果</th>
                        </tr>

                        <tbody>
                            <tr v-for="item in checkValue">
                                <td nowrap="nowrap">{{item.UpkeepItemName}}</td>
                                <!-- <td nowrap="nowrap">{{item.periodTypeNAME}}</td> -->
                                <td nowrap="nowrap">
                                    <el-radio style="padding-left: 2px;padding-right: 2px;" size="mini"
                                        v-model="item.FResult" label="0" border>不合格</el-radio>
                                    <el-radio style="padding-left: 2px;padding-right: 2px;" size="mini"
                                        v-model="item.FResult" label="1" border>合格</el-radio>
                                    <el-radio style="padding-left: 2px;padding-right: 2px;" size="mini"
                                        v-model="item.FResult" label="2" border>待定
                                    </el-radio>
                                    <!-- <el-radio size="mini" v-model="item.FResult" label="2" border>良好</el-radio>
                                    <el-radio size="mini" v-model="item.FResult" label="3" border>暂无结果</el-radio> -->
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="bottom">
                <div class="left-content">
                </div>
                <div class="right-button flex-box">
                    <van-button color="#e6c678" :disabled="ifConfirm" :loading="ifConfirm" loading-text="请稍后..."
                        @click="confirmSub" block>{{startbutton=='开始' ? '开始保养' : startbutton=='提醒' ? '开始保养' : '结束保养'}}
                    </van-button>
                </div>
            </div>
        </div>

        <van-popup v-model="showDate" position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" @confirm="confirmTime"
                @cancel="showDate = false"></van-datetime-picker>
        </van-popup>

        <van-popup v-model="scanShow" class="scanPop">
            <div class="scanLine"></div>
            <van-icon name="enlarge"></van-icon>
            <input id="autoInput" class="inputClass" inputmode="none" type="number" v-model="inputCode" ref="input"
                autofocus @keyup.enter="inputFocus()">
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            console.log(JSON.stringify(ret))
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '模具') {
                vm.formData.MouldID = row.MouldID;
                vm.formData.MouldNo = row.MouldNo;
                vm.formData.ProductName = row.ProductName;
                vm.getInitData()

            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                formData: {
                    UpkeepEquipmentID: 0, //主表ID
                    MouldNo: '',
                    MouldID: '',
                    unKeepUserID: '',
                    unKeepUserName: '',
                    unKeepUserCode: '',
                    unKeepTime: '',
                    BYReason: '正常保养',
                },
                startbutton: '开始',
                showDate: false,
                currentDate: new Date(),
                checkValue: [],
                ifConfirm: false,
                scanShow: true,
                inputCode: '',
            },
            created: function () {
                var that = this;

                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }

                that.formData.unKeepUserName = window.localStorage.getItem('loginName')
                that.formData.unKeepUserCode = window.localStorage.getItem('pin')

                console.log('api', JSON.stringify(api.pageParam))

                if (api.pageParam.historyData) {
                    that.startbutton = api.pageParam.historyData.StatusVal == '提醒' ? "提醒" : '结束'
                    that.scanShow = false
                    that.formData.UpkeepEquipmentID = api.pageParam.historyData.UpkeepEquipmentID
                    that.formData.MouldNo = api.pageParam.historyData.MouldNo
                    that.formData.MouldID = api.pageParam.historyData.MouldID
                    that.formData.ProductName = api.pageParam.historyData.ProductName
                    if (api.pageParam.historyData.BYStatus == 1) {
                        that.formData.unKeepTime = api.pageParam.historyData.BYStartTime ? api.pageParam.historyData.BYStartTime.replace('T', ' ') : ''
                    }
                    that.getInitData()
                } else {
                    that.startbutton = '开始'
                    that.formData.unKeepTime = APP.getFormatDate(new Date())

                }
            },
            methods: {
                getInitData() {
                    var that = this
                    var obj = {
                        MouldID: that.formData.MouldID,
                        UpkeepEquipmentID: that.formData.UpkeepEquipmentID
                    }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('getDeviceUnkeepTemplate_ZSMJ', obj, function (res) {
                        console.log('res', JSON.stringify(res))
                        if (res.ds.length) {
                            res.ds.map((item) => {
                                item.FResult = item.FResult.toString()
                            })
                            that.checkValue = res.ds
                        } else {
                            that.checkValue = []
                        }
                    })
                },
                onClickLeft() {
                    api.sendEvent({
                        name: 'refreshMouldUpkeep'
                    })
                    api.sendEvent({
                        name: 'refreshBrowser',
                        extra: {
                            breadData: {
                                name: '模具保养明细',
                                url: 'mouldUpkeepDetail',
                                ZS_FunctionID: 0,
                                click: true
                            }
                        }
                    })

                    api.closeFrame()

                },
                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (str == '模具') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['MouldNo'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSMould',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                confirmTime() {
                    var that = this
                    that.formData.unKeepTime = APP.getFormatDay(that.currentDate)
                    that.showDate = false
                },
                inputFocus() {
                    var that = this
                    APP.ajax('ZS_CardLogin', { P_Card: that.inputCode }, function (res) {
                        if (res.ds[0].status == 200) {
                            that.formData.unKeepUserCode = res.ds[0].pin
                            that.formData.unKeepUserName = res.ds[0].Name

                            if (that.formData.unKeepTime) { //结束保养

                            }
                            that.scanShow = false
                        } else {
                            vm.$toast(res.ds[0].msg);
                        }
                        that.inputCode = ''
                    })
                },
                confirmSub() {
                    var that = this
                    // if (!api.pageParam.historyData) { //开始保养
                    //     var obj = {
                    //         UpkeepEquipmentID: that.formData.UpkeepEquipmentID,
                    //         pin: that.formData.unKeepUserCode
                    //     }
                    //     console.log('obj', JSON.stringify(obj))
                    //     APP.ajax('ZS_MJBYStrat', obj, function (res) {
                    //         console.log('res', JSON.stringify(res))
                    //         if (res.ds[0].Result != '已开始保养') {
                    //             api.toast({
                    //                 msg: '模具开始保养失败，请重试！',
                    //                 duration: 2000,
                    //                 location: 'bottom'
                    //             });
                    //             return false
                    //         } else {
                    //             api.toast({
                    //                 msg: '模具开始保养！',
                    //                 duration: 2000,
                    //                 location: 'bottom'
                    //             });
                    //             api.sendEvent({
                    //                 name: 'refreshMouldUpkeep'
                    //             })
                    //             that.formData.unKeepTime = APP.getFormatDay(new Date())
                    //         }
                    //     })
                    // } 
                    if (that.startbutton == '开始') { //开始保养
                        var obj = {
                            UpkeepItemIDS: that.checkValue.map((item) => item.UpkeepItemID).join(','),
                            pin: that.formData.unKeepUserCode,
                            MouldID: that.formData.MouldID,
                        }
                        console.log('obj', JSON.stringify(obj))
                        APP.ajax('ZS_MJBYStrat_1', obj, function (res) {
                            console.log('res', JSON.stringify(res))
                            api.toast({
                                msg: res.ds[0].cont,
                                duration: 2000,
                                location: 'bottom'
                            });
                            api.sendEvent({
                                name: 'refreshMouldUpkeep'
                            })

                            setTimeout(() => {
                                api.sendEvent({
                                    name: 'refreshBrowser',
                                    extra: {
                                        breadData: {
                                            name: '模具保养明细',
                                            url: 'mouldUpkeepDetail',
                                            ZS_FunctionID: 0,
                                            click: true
                                        }
                                    }
                                })

                                api.closeFrame()

                            }, 1000);
                            // if (res.ds[0].Result != '已开始保养') {
                            //     api.toast({
                            //         msg: '模具开始保养失败，请重试！',
                            //         duration: 2000,
                            //         location: 'bottom'
                            //     });
                            //     return false
                            // } else {
                            //     api.toast({
                            //         msg: '模具开始保养！',
                            //         duration: 2000,
                            //         location: 'bottom'
                            //     });
                            //     api.sendEvent({
                            //         name: 'refreshMouldUpkeep'
                            //     })
                            //     that.formData.unKeepTime = APP.getFormatDay(new Date())
                            // }
                        })

                    }
                    else if (that.startbutton == '提醒') { //提醒
                        var obj = {
                            UpkeepEquipmentID: that.formData.UpkeepEquipmentID,
                            pin: that.formData.unKeepUserCode
                        }
                        console.log('obj', JSON.stringify(obj))
                        APP.ajax('ZS_MJBYStrat', obj, function (res) {
                            console.log('res', JSON.stringify(res))
                            if (res.ds[0].Result != '已开始保养') {
                                api.toast({
                                    msg: '模具开始保养失败，请重试！',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                return false
                            } else {
                                api.toast({
                                    msg: '模具开始保养！',
                                    duration: 2000,
                                    location: 'bottom'
                                });

                                that.formData.unKeepTime = APP.getFormatDay(new Date())
                                api.sendEvent({
                                    name: 'refreshMouldUpkeep'
                                })
                                setTimeout(() => {
                                    api.sendEvent({
                                        name: 'refreshBrowser',
                                        extra: {
                                            breadData: {
                                                name: '模具保养明细',
                                                url: 'mouldUpkeepDetail',
                                                ZS_FunctionID: 0,
                                                click: true
                                            }
                                        }
                                    })

                                    api.closeFrame()

                                }, 1000);

                            }
                        })
                    }
                    else {
                        // that.scanShow = true
                        var obj = {
                            FResultS: that.checkValue.map((item) => item.FResult).join(','),
                            pin: that.formData.unKeepUserCode,
                            UpkeepEquipmentID: that.formData.UpkeepEquipmentID,
                            UpkeepItemIDS: that.checkValue.map((item) => item.UpkeepItemID).join(','),
                            BYReason: that.formData.BYReason
                        }
                        console.log('obj', JSON.stringify(obj))
                        APP.ajax('ZS_MJBYEnd', obj, function (res) {
                            console.log('res', JSON.stringify(res))
                            if (res.ds[0].Result != '已结束保养') {
                                api.toast({
                                    msg: '模具结束保养，失败请重试！',
                                    duration: 2000,
                                    location: 'bottom'
                                });

                                return false
                            } else {
                                api.toast({
                                    msg: '模具结束保养！',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                api.sendEvent({
                                    name: 'refreshMouldUpkeep'
                                })

                                setTimeout(() => {
                                    api.sendEvent({
                                        name: 'refreshBrowser',
                                        extra: {
                                            breadData: {
                                                name: '模具保养明细',
                                                url: 'mouldUpkeepDetail',
                                                ZS_FunctionID: 0,
                                                click: true
                                            }
                                        }
                                    })
                                    api.closeFrame()
                                }, 1000);

                            }
                        })


                    }
                },
            }
        })

        function CheckBox1_Click() {
            var option = []

        }
    };
</script>

</html>